/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package it.polimi.registration.business.security.entity;

import java.io.Serializable;
import java.security.Timestamp;
import java.util.Calendar;
import java.util.Date;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;

/**
 *
 * @author Luca
 */
@Entity

public class Event implements Serializable {
    
    private static long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    //@NotNull(message = "May not be empty")
    private String title;
    @Temporal(TemporalType.TIMESTAMP)
    @NotNull(message = "May not be empty")
    private  Date startDate;
    @Temporal(TemporalType.TIMESTAMP)
    @NotNull(message = "May not be empty")
    private Date endDate;
    //@NotNull(message = "May not be empty")
    private Location location;
    @NotNull(message = "May not be empty")
    private String preference="false";
    @ManyToOne(targetEntity = MyForecast.class, optional = false,fetch=FetchType.EAGER)
    private MyForecast myforecast;
    @Temporal(TemporalType.TIMESTAMP)
    private Date startH;
    @Temporal(TemporalType.TIMESTAMP)
    private Date endH;
            
    private Users creator;
    
    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    public static void setSerialVersionUID(long serialVersionUID) {
        Event.serialVersionUID = serialVersionUID;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getTitle() {
        System.out.println("GET TITLE ["+this.title+"]");
        return title;
    }

    public void setTitle(String title) {
      
            this.title = title;
       
        System.out.println("SET TITLE ["+this.title+"] TO ["+title+"]");
    }

    public Date getStartDate() {
        System.out.println("GET TITLE ["+this.startDate+"]");
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
         System.out.println("SET DATE ["+this.startDate+"] TO ["+startDate+"]");

    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    /**
     * @return the location
     */
    public Location getLocation() {
        if(location==null)
            location= new Location();
        
        return location;
    }

    /**
     * @param location the location to set
     */
    public void setLocation(Location location) {
        this.location = location;
    }

    /**
     * @return the preference
     */
    public String getPreference() {
        return preference;
    }

    /**
     * @param preference the preference to set
     */
    public void setPreference(String preference) {
        this.preference = preference;
    }

    /**
     * @return the creator
     */
    public Users getCreator() {
        return creator;
    }

    /**
     * @param creator the creator to set
     */
    public void setCreator(Users creator) {
        this.creator = creator;
    }

    public Date mergedata(Date date, Date h){
        Date date1 = new Date();
        date1.setDate(date.getDate());
        date1.setMonth(date.getMonth());
        date1.setYear(date.getYear());
        date1.setHours(h.getHours());
        date1.setMinutes(h.getMinutes());
        return date1;
    }   

    /**
     * @return the startH
     */
    public Date getStartH() {
        return startH;
    }

    /**
     * @param startH the startH to set
     */
    public void setStartH(Date startH) {
        this.startH = startH;
    }

    /**
     * @return the endH
     */
    public Date getEndH() {
        return endH;
    }

    /**
     * @param endH the endH to set
     */
    public void setEndH(Date endH) {
        this.endH = endH;
    }

    /**
     * @return the myforecast
     */
    public MyForecast getMyforecast() {
        if(myforecast==null)
            myforecast= new MyForecast();
        
        return myforecast;
    }

    /**
     * @param myforecast the myforecast to set
     */
    public void setMyforecast(MyForecast myforecast) {
        this.myforecast = myforecast;
    }
}
